<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue.js</title>
    <script src="js/vue.js"></script>
</head>
<body>
    <div id="app">
        <h1>切换图片</h1>

        <!-- 图表 -->
        <div id="bag" :class="{burst:ended}"></div>

        <!-- 进度情况 -->
        <div id="bag-health">
            <div :style="{width:health+'%'}"></div>
        </div>

        <!-- 控制按钮 -->
        <div id="controls">
            <button @click="punch" v-show="!ended">使劲敲</button>
            <button @click="restart">重置</button>
        </div>
    </div>
</body>
<script>
new Vue({
    el:"#app",
    data:{
        health:100,
        ended:false
    },
    methods:{
        punch: function(){
            this.health -= 10;
            if(this.health <= 0){
                this.ended = true;
            }
        },
        restart: function(){
            this.health = 100;
            this.ended = false;
        }
    },
    computed:{

    }
});
</script>
<style>
    #bag{
        width: 200px;
        height: 500px;
        margin: 0 auto;
        background: url(img/01.png) center no-repeat;
        background-size: 80%;
    }
    #bag.burst{
        background: url(img/02.png) center no-repeat;
        background-size: 80%;
    }
    #bag-health{
        width: 200px;
        border: 2px solid #000000;
        margin: 0px auto 20px auto;
    }
    #bag-health div{
        height: 20px;
        background: crimson;
    }
    #controls{
        width: 120px;
        margin: 0 auto;
    }
</style>
</html>